<?php
/**
 * 
 * Manejador de Errores Exts
 *
 */
class Exts_Exception extends Exception
{
    protected $message = 'Unknown exception';   // exception message
    protected $code = 0;                        // user defined exception code
    protected $file;                            // source filename of exception
    protected $line;                            // source line of exception

    
    /**
     * Construye la excepcion
     * 
     * @param $message Puede ser un string, o un Exception 
     * @param $code
     */
    public function __construct($message = null, $code = 0) 
    {
    	$writer = new Zend_Log_Writer_Stream('/tmp/exts_exception.log');
		$log = new Zend_Log($writer);
		
		if( $message instanceof Exception ) {
			$message = "Message: " . $message->getMessage() . "\n" 
	            ."File: " . $message->getFile() ."\n"
	            ."Code: " . $message->getCode() ."\n"
	            ."Line: " . $message->getLine() ."\n"
	            ."Trace: " . $message->getTraceAsString() ."\n";
		}
		
		if( is_array( $message )){
			$message = print_r( $message, true );
		}
		
		$log->err( $message . " code: " .$code );
		parent::__construct( $message, $code );
    }
    
    public function render( $message ) {
    	echo "Message: " . $message->getMessage() . "<br/>" 
            ."File: " . $message->getFile() ."<br/>"
            ."Code: " . $message->getCode() ."<br/>"
            ."Line: " . $message->getLine() ."<br/>"
            ."Trace: " . $message->getTraceAsString() ."<br/>";
    	exit;
    } 
    
    
	
}
